﻿#region Using Statements

using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;

#endregion

namespace StarWarsGame
{
    /// <summary>
    /// This is a game component that implements the Game Start Scene.
    /// </summary>
    public class HelpScene : GameScene
    {
        // Misc
        protected TextMenuComponent menu;
        protected readonly Texture2D elements;
        // Audio

        protected Cue backMusic;
        // Spritebatch
        protected SpriteBatch spriteBatch = null;
        // Gui Stuff
        protected Rectangle rockRect = new Rectangle(0, 0, 536, 131);
        protected Vector2 rockPosition;
        protected Rectangle rainRect = new Rectangle(120, 165, 517, 130);
        protected Vector2 rainPosition;
        protected Rectangle enhancedRect = new Rectangle(8, 304, 375, 144);
        protected Vector2 enhancedPosition;
        protected bool showEnhanced;
        protected TimeSpan elapsedTime = TimeSpan.Zero;

        public TypingTextBox helpTextMission;
        public TypingTextBox helpTextMissionHeader;

        public TypingTextBox helpTextControlsHeading;
        public TypingTextBox helpTextPlayerControlsXwingHeading;
        public TypingTextBox helpTextPlayerControlsRebelHeading;
        public TypingTextBox helpTextPlayerControlsXwing;
        public TypingTextBox helpTextPlayerControlsRebel;

        /// <summary>
        /// Default Constructor
        /// </summary>
        /// <param name="game">Main game object</param>
        /// <param name="smallFont">Font for the menu items</param>
        /// <param name="largeFont">Font for the menu selcted item</param>
        /// <param name="background">Texture for background image</param>
        /// <param name="elements">Texture with the foreground elements</param>
        public HelpScene(Game game, SpriteFont smallFont, SpriteFont largeFont,
                            Texture2D background, Texture2D elements, SpriteBatch currentSpriteBatch)
            : base(game)
        {
            this.elements = elements;
            Components.Add(new ImageComponent(game, background,
                                            ImageComponent.DrawMode.Center, currentSpriteBatch));

           
            // Create the Menu
            //string[] items = { "Mission: Destroy the enemies before you get killed!", "Use the arrows to navigate and space to fire.", "Use X to accelerate and Z to slow down the xwing." };
            //menu = new TextMenuComponent(game, smallFont, largeFont, currentSpriteBatch);
            //menu.SetMenuItems(items);
            //Components.Add(menu);


            helpTextMissionHeader = new TypingTextBox(game, smallFont, largeFont, currentSpriteBatch, Game.Window.ClientBounds.Width / 6, 150, 40, 400, game.borderTexture, "Mission:", Color.Goldenrod);
            Components.Add(helpTextMissionHeader);

            helpTextMission = new TypingTextBox(game, smallFont, largeFont, currentSpriteBatch, Game.Window.ClientBounds.Width / 6, 180, 40, 800, game.borderTexture, "Destroy the enemies before you get killed!", Color.BlueViolet);
            Components.Add(helpTextMission);

            helpTextControlsHeading = new TypingTextBox(game, smallFont, largeFont, currentSpriteBatch, Game.Window.ClientBounds.Width / 6, 210, 40, Game.Window.ClientBounds.Width-Game.Window.ClientBounds.Width / 6, game.borderTexture, "Join the rebels as either a xwing pilot or a rebel soldier.", Color.BlueViolet);
            Components.Add(helpTextControlsHeading);

            helpTextPlayerControlsXwingHeading = new TypingTextBox(game, smallFont, largeFont, currentSpriteBatch, Game.Window.ClientBounds.Width / 4, 280, 40, Game.Window.ClientBounds.Width - Game.Window.ClientBounds.Width / 2 - Game.Window.ClientBounds.Width / 4, game.borderTexture, "Xwing Pilot:", Color.DarkRed);
            Components.Add(helpTextPlayerControlsXwingHeading);

            helpTextPlayerControlsXwing = new TypingTextBox(game, smallFont, largeFont, currentSpriteBatch, Game.Window.ClientBounds.Width / 4, 310, 40, Game.Window.ClientBounds.Width - Game.Window.ClientBounds.Width / 2 - Game.Window.ClientBounds.Width / 4, game.borderTexture, "Use the arrows to navigate and space to fire. Use X to accelerate and Z to slow down the xwing.", Color.Red);
            Components.Add(helpTextPlayerControlsXwing);


            helpTextPlayerControlsRebelHeading = new TypingTextBox(game, smallFont, largeFont, currentSpriteBatch, Game.Window.ClientBounds.Width / 2, 280, 40, Game.Window.ClientBounds.Width - Game.Window.ClientBounds.Width / 2, game.borderTexture, "Rebel soldier:", Color.DarkGreen);
            Components.Add(helpTextPlayerControlsRebelHeading);

            helpTextPlayerControlsRebel = new TypingTextBox(game, smallFont, largeFont, currentSpriteBatch, Game.Window.ClientBounds.Width / 2, 310, 40, 400, game.borderTexture, "Use the arrows to walk and the move to aim. The fire is on the left mousebutton.", Color.Green);
            Components.Add(helpTextPlayerControlsRebel);       

            // Get the current spritebatch
            spriteBatch = currentSpriteBatch;//new SpriteBatch(device);//(SpriteBatch)Game.Services.GetService(
            //                typeof(SpriteBatch));
            // Get the current audiocomponent and play the background music
            //audioComponent = (AudioComponent)
            //    Game.Services.GetService(typeof(AudioComponent));
        }

        /// <summary>
        /// Show the start scene
        /// </summary>
        public override void Show()
        {
            //audioComponent.PlayCue("newmeteor");
            //backMusic = audioComponent.GetCue("startmusic");

            //rockPosition.X = -1 * rockRect.Width;
            //rockPosition.Y = 40;
            //rainPosition.X = Game.Window.ClientBounds.Width;
            //rainPosition.Y = 180;
            //// Put the menu centered in screen
            //menu.Position = new Vector2((Game.Window.ClientBounds.Width -
            //                              menu.Width) / 2, 330);

            //// These elements will be visible when the 'Rock Rain' title
            //// is done.
            //menu.Visible = false;
            //menu.Enabled = false;
            //showEnhanced = false;

            base.Show();
        }

        /// <summary>
        /// Hide the start scene
        /// </summary>
        public override void Hide()
        {
            // backMusic.Stop(AudioStopOptions.Immediate);
            base.Hide();
        }

        /// <summary>
        /// Gets the selected menu option
        /// </summary>
        public int SelectedMenuIndex
        {
            get { return menu.SelectedIndex; }
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            //if (!menu.Visible)
            //{
            //    if (rainPosition.X >= (Game.Window.ClientBounds.Width - 595) / 2)
            //    {
            //        rainPosition.X -= 15;
            //    }

            //    if (rockPosition.X <= (Game.Window.ClientBounds.Width - 715) / 2)
            //    {
            //        rockPosition.X += 15;
            //    }
            //    else
            //    {
            //        menu.Visible = true;
            //        menu.Enabled = true;


            //        enhancedPosition =
            //            new Vector2((rainPosition.X + rainRect.Width -
            //            enhancedRect.Width / 2) - 80, rainPosition.Y);

            //        showEnhanced = true;
            //    }
            //}
            //else
            //{
            //    elapsedTime += gameTime.ElapsedGameTime;

            //    if (elapsedTime > TimeSpan.FromSeconds(1))
            //    {
            //        elapsedTime -= TimeSpan.FromSeconds(1);
            //        showEnhanced = !showEnhanced;
            //    }
            //}

            base.Update(gameTime);
        }

        /// <summary>
        /// Allows the game component to draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Draw(GameTime gameTime)
        {

            //spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState);
            //spriteBatch.Draw(elements, rockPosition, rockRect, Color.White);
            //spriteBatch.Draw(elements, rainPosition, rainRect, Color.White);
            //if (showEnhanced)
            //{
            //    spriteBatch.Draw(elements, enhancedPosition, enhancedRect,
            //                     Color.White);
            //}
            //spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}